package start.demo01.datatype.json.entity.builder;

import com.alibaba.fastjson.JSONObject;
import start.demo01.datatype.json.interfaces.Builder;

import java.util.Iterator;
import java.util.LinkedList;

public class BuilderChain extends LinkedList<Builder> {

    public static BuilderChain builder() {
        return new BuilderChain();
    }

    public BuilderChain chain(Builder builder) {
        add(builder);
        return this;
    }

    public BuilderChain(Builder... builders) {
        for (Builder builder : builders) {
            if (builder != null)
                add(builder);
        }
    }

    public void execute(JSONObject jsonObject) {
        Iterator<Builder> iterator = iterator();
        while (iterator.hasNext()) {
            Builder next = iterator.next();
            next.builde(jsonObject);
        }
    }
}
